package com.example.book.config;

import com.example.book.model.Result;
import lombok.extern.slf4j.Slf4j;
import lombok.extern.slf4j.XSlf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Hua YY
 * Date: 2024-12-22
 * Time: 17:33
 */
@Slf4j
@ResponseBody
@ControllerAdvice
public class ExceprionAdvice {
    @ExceptionHandler
    public Result handleException(Exception e){
        log.error("发生异常：e：",e);
        return Result.fail("内部错误");
    }
    @ExceptionHandler
    public Result handleException(NullPointerException e){
        log.error("发生异常：e：",e);
        return Result.fail("发生空指针异常");
    }
    @ExceptionHandler
    public Result handleException(ArithmeticException e){
        log.error("发生异常：e：",e);
        return Result.fail("发生算数异常");
    }
}
